package com.server;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Helper.*;
import com.database.*;
import java.util.*;

public class DestStatsServlet extends CustomerServlet
{
	private static final long serialVersionUID = 1L;
	private final String className = "Destination Stats Servlet: ";

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
	{
		ConnectDB();
		String id = req.getParameter("id");
		String msg = null;
				
		try 
		{
			FlightHelper.Setup(connection);
			
			ArrayList<DestInfo> list = FlightHelper.GetDestStats();
			ArrayList<DestInfo> listNoZero = new ArrayList<DestInfo>();
			
			for (int i = 0; i < list.size(); i++)
			{
				DestInfo info = list.get(i);
				if (list.get(i).count != 0)
				{
					listNoZero.add(info);
				}
			}
			
			req.setAttribute("id", id);
			
			if (listNoZero.size() > 0)
			{		
				req.setAttribute("destList", listNoZero);
				req.getRequestDispatcher("admin/destination_stats.jsp").forward(req, resp);
			}
			else
			{
				msg = "No reservations made in database";
				req.setAttribute("msg", msg);
				req.getRequestDispatcher("admin/admin_error.jsp").forward(req, resp);
			}
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
	}

}

